package com.example.composetutorial

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.composetutorial.ui.theme.ComposeTutorialTheme

class ComponentsActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            ClickCounter(  )
            //Scaffold_1()

           /* val intent = Intent(
                this,
               BlankFragment.kt
            )
            startActivity(intent)*/

          /*val intent = Intent(
            ).setClassName(this, "MainActivity.kt")
            startActivity(intent)*/

/*ComposeTutorialTheme {
   Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
       Greeting(
           name = "Android",
           modifier = Modifier.padding(innerPadding)
       )
   }
}*/
/*MyText(name ="MyText" )*/
/*MyText("MyText" )*/

/*AndroidView(factory = { context ->
   WebView(context).apply {
       settings.javaScriptEnabled = true
       settings.blockNetworkLoads=true

       settings.cacheMode= WebSettings.LOAD_DEFAULT
       webViewClient = WebViewClient()
       loadUrl("https://cn.bing.com/")
       //loadUrl("https://jetpackcompose.cn/")

   }
}, modifier = Modifier.fillMaxSize())*/

/*AndroidView(factory = { context ->
   Button(context).apply {
   text="Button"
       setBackgroundColor(Color.RED)
       //setBackgroundResource(R.drawable.bingwallpaper)
       setOnClickListener {
           println("Button")
       }
   }
}, modifier = Modifier.size(300.dp))*/
//Factory({"String" -> Unit})
//Factory({Greeting_1("str")})
//AddToFav()
val  button: Button =  Button(applicationContext).apply { text="button" }

//val  constraintLayout:ConstraintLayout =   findViewById<ConstraintLayout>(R.id.constraintLayout)
//val  constraintLayout:ConstraintLayout =  findViewById(R.id.constraintLayout)
/*val  constraintLayout:ConstraintLayout =  ConstraintLayout(applicationContext).apply {
   addView(button)
}*/

//val chipGroup : ChipGroup =   findViewById<ChipGroup>(R.id.chipGroup)
/*val chipGroup : ChipGroup = ChipGroup(applicationContext)  .apply { id=0}
val chipGroup_1 : ChipGroup =   findViewById<ChipGroup>(0)*/
/*AndroidView(factory = { context ->
   ConstraintLayout(context).apply {
layout(10,10,200,200)
       //layoutParams
addView(constraintLayout)
       setBackgroundColor(Color.Red.toArgb())
//addView(chipGroup_1)

   }
}, modifier = Modifier.fillMaxSize())*/
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
ComposeTutorialTheme {
Greeting("Android")
}
}
/*
package com.example.composetutorial

import SampleData
import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.composetutorial.ui.theme.ComposeTutorialTheme


class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {

*/
/*ComposeTutorialTheme {
   Surface(modifier = Modifier.fillMaxSize()) {
       MessageCard(Message("Android", "Jetpack Compose"))
   }
}*//*

ComposeTutorialTheme {
   Conversation(SampleData.conversationSample)
}
}
}
}

data class Message(val author: String, val body: String)
// ...

@Composable
fun MessageCard(msg: Message) {
Row(modifier = Modifier.padding(all = 8.dp)) {
Image(
painter = painterResource(R.drawable.profile_picture),
contentDescription = null,
modifier = Modifier
   .size(40.dp)
   .clip(CircleShape)
   .border(1.5.dp, MaterialTheme.colorScheme.secondary, CircleShape)
)
Spacer(modifier = Modifier.width(8.dp))

// We keep track if the message is expanded or not in this
// variable
var isExpanded by remember { mutableStateOf(false) }
// surfaceColor will be updated gradually from one color to the other
val surfaceColor by animateColorAsState(
if (isExpanded) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.surface,
)

// We toggle the isExpanded variable when we click on this Column
Column(modifier = Modifier.clickable { isExpanded = !isExpanded


}) {
Text(
   text = msg.author,
   color = MaterialTheme.colorScheme.secondary,
   style = MaterialTheme.typography.titleSmall
)

Spacer(modifier = Modifier.height(4.dp))

Surface(
   shape = MaterialTheme.shapes.medium,
   shadowElevation = 1000.dp,
   // surfaceColor color will be changing gradually from primary to surface
   //color = surfaceColor,
   // animateContentSize will change the Surface size gradually
   modifier = Modifier
       .animateContentSize()
       .padding(1.dp)
) {
   Text(
       text = msg.body,
       modifier = Modifier.padding(all = 4.dp),
       // If the message is expanded, we display all its content
       // otherwise we only display the first line
       //maxLines = if (isExpanded) Int.MAX_VALUE else 1,
       maxLines = if (isExpanded) 3 else 1,
       style = MaterialTheme.typography.bodyMedium
   )
}
}
}
}






@Preview(name = "Light Mode")
@Preview(
uiMode = Configuration.UI_MODE_NIGHT_YES,
showBackground = true,
name = "Dark Mode"
)

@Composable
fun PreviewMessageCard() {
ComposeTutorialTheme {
Surface {
MessageCard(
   msg = Message("Lexi", "Take a look at Jetpack Compose, it's great!")
)
}
}

}
@Composable
fun Conversation(messages: List<Message>) {
LazyColumn {
items(messages) { message ->
MessageCard(message)
}
}
*/
/*LazyRow {
items(messages) { message ->
MessageCard(message)
}
}*//*

}

@Preview
@Composable
fun PreviewConversation() {
ComposeTutorialTheme {
Conversation(SampleData.conversationSample)
}
}
*/


